package thread;

/**
 * @author HanDianzhi
 * @version 1.0
 * @description: 创建线程的五种写法
 * @date 2022/7/5 18:06
 */
public class ThreadFiveCreate {
    public static void main(String[] args) {
        Thread t1 = new T1();
        RunnableMethod runnableMethod = new RunnableMethod();
        Thread t2 = new Thread(runnableMethod);
        Thread t3 = new Thread(){
            @Override
            public void run() {
                System.out.println("继承 Thread, 重写 run, 使用匿名内部类");
            }
        };

        Thread t4 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("实现 Runnable, 重写 run, 使用匿名内部类");
            }
        });
        Thread t5 = new Thread(() -> System.out.println("使用 lambda 表达式"));

        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();


    }
}
/**
 * 继承 Thread, 重写 run
 */
class T1 extends Thread{
    @Override
    public void run() {
        System.out.println("继承 Thread, 重写 run");
    }
}

/**
 * 实现 Runnable, 重写 run
 */
//class RunnableMethod implements Runnable{
//    @Override
//    public void run() {
//        System.out.println("实现 Runnable, 重写 run");
//    }
//}